/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package stuff.web;

import org.springframework.web.bind.support.WebBindingInitializer;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.context.request.WebRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomCollectionEditor;
import java.util.List;
import stuff.DictionaryManager;

/**
 *
 * @author Николай
 */
public class BinderInit implements WebBindingInitializer {

    @Autowired
    private DictionaryManager dicMng;

    @Override
    public void initBinder(WebDataBinder binder, WebRequest request) {

//        binder.registerCustomEditor(Country.class, new PropertyEditorSupport() {
//
//            @Override
//            public void setAsText(String text) throws IllegalArgumentException {
//                Country c = dicMng.getCountry(text);
//                setValue(c);
//            }
//        });

        binder.registerCustomEditor(List.class, new CustomCollectionEditor(List.class) {

            @Override
            protected Object convertElement(Object element) {
                return element;
            }
        });
    }
}
